package com.collectplus.express.parcel;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.collectplus.express.BaseActivity2;
import com.collectplus.express.R;
import com.collectplus.express.logic.AppTab;
import com.collectplus.express.parcel.fragment.ParcelSendAllFragment;
import com.collectplus.express.parcel.fragment.ParcelSendNoPayFragment;
import com.collectplus.express.parcel.fragment.ParcelSendWaitFragment;
import com.collectplus.express.parcel.fragment.ParcelSendedFragment;

import droid.frame.activity.title.TitleRes;
import droid.frame.view.ViewPagerExt;

/**
 * 寄出的包裹
 * 
 * @author kaka<br>
 *         2017-1-6下午5:44:07
 */
public class ParcelSendActivity extends BaseActivity2 {
	/**
	 * 进入页面默认选择的item
	 */
	private int selectItem;
	private BaseParcelFragment mFragment1, mFragment2, mFragment3, mFragment4;

	@Override
	@SuppressLint("ResourceAsColor")
	protected void onCreate(Bundle savedInstanceState) {
		selectItem = getIntent().getIntExtra("item", 0);
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void findViewById()  {
		setContentView(R.layout.parcel_send_main);
		super.findViewById();
		// getAppTitle().setCommonTitle("寄出的包裹");
		getAppTitle().setCommonTitle("寄出的包裹", new TitleRes(R.drawable.ic_search, new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(getContext(), ParcelSearchActivity.class);
				startActivity(intent);
			}
		}));
		((TextView) findViewById(R.id.title_middle_text)).setGravity(Gravity.LEFT);
		findViewById(R.id.app_title_layout).setBackgroundColor(Color.parseColor("#fbfbfb"));
		TextView[] mTags = new TextView[4];
		mTags[0] = (TextView) findViewById(R.id.send_parcel_tab1);
		mTags[1] = (TextView) findViewById(R.id.send_parcel_tab2);
		mTags[2] = (TextView) findViewById(R.id.send_parcel_tab3);
		mTags[3] = (TextView) findViewById(R.id.send_parcel_tab4);

		initFragment();

		ViewPagerExt mViewPager = (ViewPagerExt) findViewById(R.id.viewpager);
		ImageView mImgLine = (ImageView) findViewById(R.id.my_parcel_line_img);
		mViewPager.setSupportScroll(false);
		mViewPager.setFragmentItems(getSupportFragmentManager(), mFragment1, mFragment2, mFragment3, mFragment4);
		mViewPager.setSupportScroll(true);
		AppTab appTab = new AppTab(getContext(), 0);
		appTab.initPosition(mViewPager, mImgLine, mTags);

		mViewPager.setCurrentItem(selectItem, true);
	}

	private void initFragment() {
		mFragment1 = new ParcelSendNoPayFragment();
		Bundle bundle1 = new Bundle();
		bundle1.putInt("type", 0);
		mFragment1.setArguments(bundle1);
		Bundle bundle2 = new Bundle();
		bundle2.putInt("type", 1);
		mFragment2 = new ParcelSendWaitFragment();
		mFragment2.setArguments(bundle2);
		Bundle bundle3 = new Bundle();
		bundle3.putInt("type", 2);
		mFragment3 = new ParcelSendedFragment();
		mFragment3.setArguments(bundle3);
		Bundle bundle4 = new Bundle();
		bundle4.putInt("type", 3);
		mFragment4 = new ParcelSendAllFragment();
		mFragment4.setArguments(bundle4);
	}
}
